package com.qf.bbapi.controller;

import com.qf.bbapi.anno.Token;
import com.qf.bbapi.config.SystemConfig;
import com.qf.bbapi.entity.Address;
import com.qf.bbapi.service.intf.AddressService;
import com.qf.bbapi.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/api/address/")
@Api(tags = "地址相关接口")
@CrossOrigin
public class AddressController {
    @Resource
    private AddressService addressService;

    @Token
    @GetMapping("all.do")
    @ApiOperation(value = "查询所有地址")
    public R queryAll(HttpServletRequest request){
        return addressService.selectAllAddress(request.getIntHeader(SystemConfig.TOKEN_HEADER));
    }

    @PostMapping("add.do")
    @ApiOperation(value = "添加收货地址")
    public R add(@RequestBody Address address){
        return addressService.addAddress(address);
    }

    @GetMapping("one.do")
    @ApiOperation(value = "查询单个")
    public R selectOne(int id){
        return addressService.selectOne(id);
    }

    @PostMapping("update.do")
    @ApiOperation(value = "修改")
    public R update(@RequestBody Address address){
        return addressService.update(address);
    }

    @GetMapping("del.do")
    @ApiOperation(value = "删除")
    public R delete(int id){
        return addressService.delete(id);
    }
}
